class Carousel {
  constructor() {
    this.container = document.querySelector('.carousel-container');
    this.slides = [
      {
        image: './images/2.png',
        description: '古风武侠剧本'
      },
      {
        image: './images/3.png',
        description: '现代都市剧本'
      },
      {
        image: './images/4.png',
        description: '科幻题材剧本'
      },
      {
        image: './images/5.png',
        description: '悬疑推理剧本'
      },
      {
        image: './images/7.png',
        description: '奇幻冒险剧本'
      }
    ];

    this.currentSlide = 0;
    this.init();
  }

  init() {
    // 创建轮播图内容
    this.slides.forEach(slide => {
      const slideDiv = document.createElement('div');
      slideDiv.className = 'carousel-slide';
      slideDiv.innerHTML = `
                <img src="${slide.image}" alt="剧本示例">
                <p>${slide.description}</p>
            `;
      this.container.appendChild(slideDiv);
    });

    // 绑定按钮事件
    document.querySelector('.carousel-prev').addEventListener('click', () => this.move('prev'));
    document.querySelector('.carousel-next').addEventListener('click', () => this.move('next'));

    // 自动轮播
    setInterval(() => this.move('next'), 5000);
  }

  move(direction) {
    if (direction === 'next') {
      this.currentSlide = (this.currentSlide + 1) % this.slides.length;
    } else {
      this.currentSlide = (this.currentSlide - 1 + this.slides.length) % this.slides.length;
    }

    this.container.style.transform = `translateX(-${this.currentSlide * 100}%)`;
  }
}

// 初始化轮播图
document.addEventListener('DOMContentLoaded', () => {
  new Carousel();
}); 